import 'package:pull_to_refresh/pull_to_refresh.dart';

extension RefreshControllerExt on RefreshController {
  finishRefreshOrLoadMore(List data, bool refresh, List oldData, Function update) {
    if (refresh) {
      oldData.clear();
      if (data.isEmpty) {
        refreshToIdle();
      } else {
        refreshCompleted(resetFooterState: true);
      }
    } else {
      if (data.isEmpty) {
        loadNoData();
      } else {
        loadComplete();
      }
    }

    oldData.addAll(data);
    update.call();
  }
}
